﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:s="clr-namespace:DiagramDesigner"
                    xmlns:c="clr-namespace:DiagramDesigner.Controls">
  <Style TargetType="{x:Type s:Connection}">
    <Style.Resources>
      <!-- Style for the ConnectorAdorner thumbs -->
      <Style x:Key="ConnectionAdornerThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Width" Value="12"/>
        <Setter Property="Height" Value="12"/>
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="RenderTransform">
          <Setter.Value>
            <TranslateTransform X="-6" Y="-6"/>
          </Setter.Value>
        </Setter>
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type Thumb}">
              <Rectangle Fill="#AADCDCDC" Stroke="DodgerBlue" StrokeThickness="1" RadiusX="0" RadiusY="0"/>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
      <!-- Arrow Grid Style -->
      <Style x:Key="ArrowGridStyle" TargetType="Grid">
        <Setter Property="Width" Value="10"/>
        <Setter Property="Height" Value="10"/>
        <Setter Property="RenderTransform">
          <Setter.Value>
            <TranslateTransform X="-5" Y="-5"/>
          </Setter.Value>
        </Setter>
      </Style>
      <!-- base style for all arrow shapes -->
      <Style x:Key="ArrowSymbolBaseStyle" TargetType="Path">
        <Setter Property="Fill" Value="{StaticResource SolidBorderBrush}"/>
        <Setter Property="Stretch" Value="Fill"/>
      </Style>
      <!-- Arrow -->
      <Style x:Key="Arrow" TargetType="Path" BasedOn="{StaticResource ArrowSymbolBaseStyle}">
        <Setter Property="Data" Value="M0,0 8,4 0,8 Z"/>
      </Style>
      <!-- Diamond  -->
      <Style x:Key="Diamond" TargetType="Path" BasedOn="{StaticResource ArrowSymbolBaseStyle}">
        <Setter Property="Data" Value="M-5,0 0,-5 5,0 0,5 Z"/>
      </Style>
    </Style.Resources>
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type s:Connection}">
          <Canvas DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}" >
            <Path Name="PART_ConnectionPath"
                  StrokeThickness="2"
                  Stroke="{StaticResource SolidBorderBrush}"
                  StrokeStartLineCap="Round"
                  StrokeEndLineCap="Round"
                  StrokeLineJoin="Round"
                  StrokeDashArray="{Binding StrokeDashArray}"
                  SnapsToDevicePixels="True"
                  Data="{Binding PathGeometry}">
            </Path>
            <Grid Style="{StaticResource ArrowGridStyle}"
                  Canvas.Left="{Binding AnchorPositionSource.X}"
                  Canvas.Top="{Binding AnchorPositionSource.Y}">
              <Path Name="PART_SourceAnchorPath"/>
              <Grid.LayoutTransform>
                <RotateTransform Angle="{Binding AnchorAngleSource}"/>
              </Grid.LayoutTransform>
            </Grid>
            <Grid Style="{StaticResource ArrowGridStyle}"
                  Canvas.Left="{Binding AnchorPositionSink.X}"
                  Canvas.Top="{Binding AnchorPositionSink.Y}">
              <Path Name="PART_SinkAnchorPath"/>
              <Grid.LayoutTransform>
                <RotateTransform Angle="{Binding AnchorAngleSink}"/>
              </Grid.LayoutTransform>
            </Grid>

            <!--Uncomment this to show default label text-->
            <!--<TextBlock Width="100" Height="35" Text="Label"                       
                       Canvas.Left="{Binding LabelPosition.X}"
                       Canvas.Top="{Binding LabelPosition.Y}">
              <TextBlock.RenderTransform>
                <TranslateTransform X="5" Y="5"/>
              </TextBlock.RenderTransform>
            </TextBlock>-->

            <Canvas.BitmapEffect>
              <DropShadowBitmapEffect Color="Gray" Direction="315" ShadowDepth="10" Softness="0" Opacity="0.1"/>
            </Canvas.BitmapEffect>
          </Canvas>
          <ControlTemplate.Triggers>
            <DataTrigger Value="Arrow" Binding="{Binding RelativeSource={RelativeSource Self},Path=SourceArrowSymbol}">
              <Setter TargetName="PART_SourceAnchorPath" Property="Style" Value="{StaticResource Arrow}"/>
            </DataTrigger>
            <DataTrigger Value="Diamond" Binding="{Binding RelativeSource={RelativeSource Self},Path=SourceArrowSymbol}">
              <Setter TargetName="PART_SourceAnchorPath" Property="Style" Value="{StaticResource Diamond}"/>
            </DataTrigger>
            <DataTrigger Value="Arrow" Binding="{Binding RelativeSource={RelativeSource Self},Path=SinkArrowSymbol}">
              <Setter TargetName="PART_SinkAnchorPath" Property="Style" Value="{StaticResource Arrow}"/>
            </DataTrigger>
            <DataTrigger Value="Diamond" Binding="{Binding RelativeSource={RelativeSource Self},Path=SinkArrowSymbol}">
              <Setter TargetName="PART_SinkAnchorPath" Property="Style" Value="{StaticResource Diamond}"/>
            </DataTrigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>
